exports.addCustomerFollowRecord = function (req, res) {

  var bodyParams = req.routeInfo.bodyParams;

  var openids = "";

  function addCustomerFollow(cb) {

    R.SEND_HTTP(
      req,
      res, {
        url: CORE_APIConfig.coreAPI.artCustomerFollowRecordUpdate.Request_Api_Url,
        method: 'POST',
        data: {
          cfr_id: bodyParams.cfr_id,
          cfr_comment: bodyParams.cfr_comment,
          cfr_comment_user: bodyParams.cfr_comment_user,
          update_where: 'cfr_id',
        }
      },
      function (data) {

        cb();

      }
    )

  }

  function searchUserOpenId(cb){

    
    R.SEND_HTTP(
      req,
      res,
      {
          url: CORE_APIConfig.coreAPI.userSearch.Request_Api_Url + "/u_id/" + bodyParams.uid,
          method: 'POST',
          data: {
              fields: ['u_openid'].join(",")
          }
      },
      function (data) {

  
          if(data.result.data.length > 0){
            openids = data.result.data[0].u_openid;
          }

          cb();

      }
  )

  }

  function sendSms(cb) {

    var params = {
      type: "genJinBeiDianPing",
      name: bodyParams.cfr_comment_user,
      organizationName: bodyParams.organizationName,
      openid: openids,
      // openid:'o2UdI0uia55ETG5ye30HbcYISyVc',
      goUrls: 'http://crm.hxzbi.com/CRM/#/historyFollow?customerId=' + bodyParams.customerId
    };

    R.SEND_HTTP(
      req,
      res, {
        url: config.server.ip + ":" + config.server.port + CORE_APIConfig.coreAPI.templateMessagesSent.Request_Api_Name,
        method: 'POST',
        data: params
      },
      function(data) {

        cb();

      }
    )

  }

  F.Serial([
    addCustomerFollow,
    searchUserOpenId,
    sendSms
  ], () => {
    RES.successResponse(res);
  })


}